package mya.mes.mdc.model.tag.convert;

import com.alibaba.fastjson.JSONObject;
import mya.mes.mdc.model.tag.AlarmTag;
import mya.mes.mdc.model.tag.MdcTag;

import java.util.Map;


public class MdcTagConverter {

  public static void fromJson(JSONObject json, MdcTag obj) {
    for (java.util.Map.Entry<String, Object> member : json.entrySet()) {
      switch (member.getKey()) {
        case "alarmTag":
          if (member.getValue() instanceof Map) {
            obj.setAlarmTag(new AlarmTag((Map)member.getValue()));
          }
          break;
        case "area":
          if (member.getValue() instanceof String) {
            obj.setArea((String)member.getValue());
          }
          break;
        case "dataType":
          if (member.getValue() instanceof String) {
            obj.setDataType((String)member.getValue());
          }
          break;
        case "description":
          if (member.getValue() instanceof String) {
            obj.setDescription((String)member.getValue());
          }
          break;
        case "digitsTag":
          if (member.getValue() instanceof Boolean) {
            obj.setDigitsTag((Boolean)member.getValue());
          }
          break;
        case "key":
          if (member.getValue() instanceof String) {
            obj.setKey((String)member.getValue());
          }
          break;
        case "plcAddress":
          if (member.getValue() instanceof String) {
            obj.setPlcAddress((String)member.getValue());
          }
          break;
        case "plcTagType":
          if (member.getValue() instanceof String) {
            obj.setPlcTagType((String)member.getValue());
          }
          break;
        case "posteTag":
          if (member.getValue() instanceof Boolean) {
            obj.setPosteTag((Boolean)member.getValue());
          }
          break;
        case "section":
          if (member.getValue() instanceof String) {
            obj.setSection((String)member.getValue());
          }
          break;
        case "shop":
          if (member.getValue() instanceof String) {
            obj.setShop((String)member.getValue());
          }
          break;
        case "startRunningTag":
          if (member.getValue() instanceof Boolean) {
            obj.setStartRunningTag((Boolean)member.getValue());
          }
          break;
        case "statusMaintTag":
          if (member.getValue() instanceof Boolean) {
            obj.setStatusMaintTag((Boolean)member.getValue());
          }
          break;
        case "statusProdTag":
          if (member.getValue() instanceof Boolean) {
            obj.setStatusProdTag((Boolean)member.getValue());
          }
          break;
        case "stopRunningTag":
          if (member.getValue() instanceof Boolean) {
            obj.setStopRunningTag((Boolean)member.getValue());
          }
          break;
        case "tagIndex":
          if (member.getValue() instanceof Number) {
            obj.setTagIndex(((Number)member.getValue()).intValue());
          }
          break;
        case "tagName":
          if (member.getValue() instanceof String) {
            obj.setTagName((String)member.getValue());
          }
          break;
        case "tagPrefix":
          if (member.getValue() instanceof String) {
            obj.setTagPrefix((String)member.getValue());
          }
          break;
        case "viewTagName":
          if (member.getValue() instanceof String) {
            obj.setViewTagName((String)member.getValue());
          }
          break;
      }
    }
  }



  public static void toJson(MdcTag obj, JSONObject json) {
    if (obj.getAlarmTag() != null) {
      json.put("alarmTag", obj.getAlarmTag().toJson());
    }
    if (obj.getArea() != null) {
      json.put("area", obj.getArea());
    }
    if (obj.getDataType() != null) {
      json.put("dataType", obj.getDataType());
    }
    if (obj.getDescription() != null) {
      json.put("description", obj.getDescription());
    }
    json.put("digitsTag", obj.isDigitsTag());
    if (obj.getKey() != null) {
      json.put("key", obj.getKey());
    }
    if (obj.getPlcAddress() != null) {
      json.put("plcAddress", obj.getPlcAddress());
    }
    if (obj.getPlcTagType() != null) {
      json.put("plcTagType", obj.getPlcTagType());
    }
    json.put("posteTag", obj.isPosteTag());
    if (obj.getSection() != null) {
      json.put("section", obj.getSection());
    }
    if (obj.getShop() != null) {
      json.put("shop", obj.getShop());
    }
    json.put("startRunningTag", obj.isStartRunningTag());
    json.put("statusMaintTag", obj.isStatusMaintTag());
    json.put("statusProdTag", obj.isStatusProdTag());
    json.put("stopRunningTag", obj.isStopRunningTag());
    json.put("tagIndex", obj.getTagIndex());
    if (obj.getTagName() != null) {
      json.put("tagName", obj.getTagName());
    }
    if (obj.getTagPrefix() != null) {
      json.put("tagPrefix", obj.getTagPrefix());
    }
    if (obj.getViewTagName() != null) {
      json.put("viewTagName", obj.getViewTagName());
    }
  }
}
